package com.gy.api.pc.filings.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.*;
import com.gy.api.pc.clap.domain.vo.PageCulvertApprovalVO;
import com.gy.api.pc.enterprise.domain.vo.EnterpriseCompleteVO;
import com.gy.api.pc.examine.domain.vo.ExamineCompleteUserVO;
import com.gy.api.pc.examine.domain.vo.ExamineCompleteVO;
import com.gy.api.pc.filings.domain.vo.*;
import com.gy.api.pc.filings.service.IPatentApplicationService;
import com.gy.api.pc.sys.user.domain.vo.SysUserSearchVO;
import com.gy.api.pc.sys.user.domain.vo.SysUserVO;
import com.gy.api.pc.sys.user.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/wcPatentApplication")
@Api( tags = ApiIndex.PatentApplicationController)
@Slf4j
public class PatentApplicationController {
    @Autowired
    IPatentApplicationService service;

    @ApiOperation("剧本备案申请-查询列表-全部")
    @GetMapping("/list")
    @ResponseBody
    public R<RestPage<List<WcContentExamineListVO>>> list(@ApiParam(value = "查询参数") @ModelAttribute WcContentExamineSearchVO searchVO)  {
        searchVO.setType(null);
        List<WcContentExamineListVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }


    @ApiOperation("剧本备案申请-【受理】列表")
    @GetMapping("/acceptanceList")
    @ResponseBody
    public R<RestPage<List<WcContentExamineListVO>>> acceptanceList(@ApiParam(value = "查询参数") @ModelAttribute WcContentExamineSearchVO searchVO)  {
        searchVO.setApprovalUserId(StpUtil.getLoginIdAsString());
        searchVO.setNodeName(Constants.EXAMINE_SCRIPT_FILING[1]);
        List<WcContentExamineListVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation("剧本备案申请-【专家评审】列表")
    @GetMapping("/expertReviewList")
    @ResponseBody
    public R<RestPage<List<WcContentExamineListVO>>> expertReviewList(@ApiParam(value = "查询参数") @ModelAttribute WcContentExamineSearchVO searchVO)  {
        searchVO.setApprovalUserId(StpUtil.getLoginIdAsString());
        searchVO.setNodeName(Constants.EXAMINE_SCRIPT_FILING[2]);
        List<WcContentExamineListVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation("剧本备案申请-【公示发证】列表")
    @GetMapping("/publicizeCertificationList")
    @ResponseBody
    public R<RestPage<List<WcContentExamineListVO>>> publicizeCertificationList(@ApiParam(value = "查询参数") @ModelAttribute WcContentExamineSearchVO searchVO)  {
        searchVO.setApprovalUserId(StpUtil.getLoginIdAsString());
        searchVO.setNodeName(Constants.EXAMINE_SCRIPT_FILING[4]);
        List<WcContentExamineListVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation("剧本备案申请-【审查决定】列表")
    @GetMapping("/reviewDecisionList")
    @ResponseBody
    public R<RestPage<List<WcContentExamineListVO>>> reviewDecisionList(@ApiParam(value = "查询参数") @ModelAttribute WcContentExamineSearchVO searchVO)  {
        searchVO.setApprovalUserId(StpUtil.getLoginIdAsString());
        searchVO.setNodeName(Constants.EXAMINE_SCRIPT_FILING[3]);
        List<WcContentExamineListVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }


    @ApiOperation("完成审批/受理-不指派专家")
    @PostMapping("/complete")
    @SaCheckLogin
    public R complete(@RequestBody ExamineCompleteVO taskCompleteDto){
        service.completeTask(taskCompleteDto);
        return new R();
    }


    @ApiOperation("受理-指派专家")
    @PostMapping("/complete_user")
    @SaCheckLogin
    public R complete_user(@RequestBody ExamineCompleteUserVO taskCompleteDto){
        service.completeTaskUser(taskCompleteDto);
        return new R();
    }


    @Autowired
    private ISysUserService sysUserService;

    @ApiOperation(value = "查询专家用户列表（状态和角色ID 有可以不用管）")
    @GetMapping(value = "/user_list")
    @SaCheckLogin
    public R<RestPage<List<SysUserVO>>> user_list(
            @ApiParam(value = "查询参数") @ModelAttribute SysUserSearchVO searchVO) {
        searchVO.setUseState(1);
        if(StringUtils.isBlank(searchVO.getRoleId())){
            searchVO.setRoleId(Constants.EXAMINE_JIA_ROLE);
        }
        List<SysUserVO> list = sysUserService.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    /**
     * 剧本备案申请详情
     */
    @ApiOperation("剧本备案申请详情")
    @GetMapping("/selectById/{id}")
    @ResponseBody
    public R<WcPatentApplicationDetailVO> selectById(@PathVariable("id") String id) {
        WcPatentApplicationDetailVO vo = service.selectWcPatentApplicationDetailVOById(id);
        return new R(vo);
    }



    @ApiOperation("【新】新增反馈国家电影局信息")
    @PostMapping("/add_recommendation")
    @ResponseBody
    public R addRecommendation(@RequestBody WcPatentApplicationRecommendationAddVO saveVO) throws Exception {
        service.addRecommendation(saveVO);
        return new R();
    }


    @ApiOperation("【新】查询反馈国家电影局信息")
    @GetMapping("/get_recommendation")
    public R<List<WcPatentApplicationRecommendationVO>> get_recommendation(@ApiParam(value = "查询参数") @ModelAttribute IDEntity saveVO) throws Exception {
        return new R(service.getRecommendationList(saveVO));
    }
//
//    /**
//     * 查询影片内容审查--【公示信息】列表
//     */
//    @ApiOperation("影片内容审查--查询影片内容审查【公示信息】列表")
//    @PreAuthorize("@ss.hasPermi('system:contentExamine:list')")
//    @PostMapping("/publicityInfoList")
//    @ResponseBody
//    public AjaxResult<Page<WcContentExaminePublicityInfoListVO>> publicityInfoList(@RequestBody WcContentExaminePublicityInfoListDto dto)  {
//        Page<WcContentExaminePublicityInfoListVO> list = wcContentExamineService.publicityInfoList(dto);
//        return success(list);
//    }
//
//    // todo 影片审查结束
//
//    /**
//     * 导出影片内容审查列表
//     */
//    @ApiOperation("导出影片内容审查列表")
//    @PreAuthorize("@ss.hasPermi('system:contentExamine:export')")
//    @Log(title = "影片内容审查", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(@RequestBody WcContentExamineSelectListDto dto) {
//        Page<WcContentExamineSelectListVO> list = wcContentExamineService.getList(dto);
//        ExcelUtil<WcContentExamineSelectListVO> util = new ExcelUtil<>(WcContentExamineSelectListVO.class);
//        return util.exportExcel(list.getRecords(), "影片内容审查数据");
//    }
//
//
//    /**
//     * 影片内容审查详情
//     */
//    @ApiOperation("影片内容审查详情")
//    //@RequiresPermissions("system:application:edit")
//    @PreAuthorize("@ss.hasPermi('system:contentExamine:detail')")
//    @GetMapping("/edit/{id}")
//    @ResponseBody
//    public AjaxResult edit(@PathVariable("id") Long id) {
//        WcContentExamineDetailVO vo = wcContentExamineService.selectWcContentExamineDetailVOById(id);
//        return success(vo);
//    }
//
//    /**
//     * 修改保存影片内容审查
//     */
//    @ApiOperation("修改影片内容审查")
//    @PreAuthorize("@ss.hasPermi('system:contentExamine:edit')")
//    @Log(title = "影片内容审查", businessType = BusinessType.UPDATE)
//    @PostMapping("/edit")
//    @ResponseBody
//    public AjaxResult editSave(@RequestBody WcContentExamine wcContentExamine) {
//        return toAjax(wcContentExamineService.updateWcContentExamine(wcContentExamine));
//    }
//
//    /**
//     * 删除影片内容审查
//     */
//    @ApiOperation("删除影片内容审查")
//    //@RequiresPermissions("system:application:remove")
//    @PreAuthorize("@ss.hasPermi('system:contentExamine:remove')")
//    @Log(title = "影片内容审查", businessType = BusinessType.DELETE)
//    @PostMapping("/remove")
//    @ResponseBody
//    public AjaxResult remove(Long id) {
//        //删除附件
//        ancillaryService.remove(Wrappers.lambdaQuery(WcContentExamineAncillary.class).
//                eq(WcContentExamineAncillary::getWcContentExamineId,id));
//        return toAjax(wcContentExamineService.removeById(id));
//    }

}
